package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

//bufio是在file的基础上封装了一层API，支持更多的功能。
func main() {
	file, err := os.Open("D:\\go_project\\golang_study\\basic\\文件操作\\test.txt")
	if err != nil {
		fmt.Println("open file failed,err:", err)
		return
	}
	defer file.Close()
	reader := bufio.NewReader(file)
	for {
		readLine, err := reader.ReadString('\n')
		if err == io.EOF {
			if len(readLine) > 0 {
				fmt.Println(readLine)
			}
			fmt.Println("文件读完了")
			break
		}
		if err != nil {
			fmt.Println("read file failed,err:", err)
			return
		}
		fmt.Print(readLine)

	}
}
